package com.yyq.thread;

/**
 * @author yyq
 * @create 2021-08-02 18:05
 */
public class MyThread extends Thread {

    String name;

    public MyThread(String name){
        this.name=name;
    }

    @Override
    public void run() {
        for(int i=0;i<10;i++)
            System.out.println(Thread.currentThread().getName()+"------"+i);

    }

}

class test{
    public static void main(String[] args) {
        //创建Thread匿名子类

        MyThread thread_1=new MyThread(Thread.currentThread().getName());
        MyThread thread_2=new MyThread(Thread.currentThread().getName());
        thread_1.start();

        thread_2.start();
        thread_1.setName("线程一");
        thread_1.setPriority(10);
        System.out.println(thread_1.getPriority());
        new Thread(){
            @Override
            public void run() {
                this.setName("匿名");
                System.out.println(this.getName());
                for(int i=0;i<10;i++){
                    System.out.println(Thread.currentThread().getName()+"------"+i);
                    if(i==2) {
                        try {
                            thread_1.join();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }.start();

        System.out.println(Thread.currentThread().getName());
    }
}